<template>
  <div>

    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="#">社团管理</a></el-breadcrumb-item>
      <el-breadcrumb-item>社团信息</el-breadcrumb-item>
    </el-breadcrumb>
    <br/>
    <span>社团名称 &nbsp;&nbsp;</span>
    <el-input class="inputMax" v-model="club.name" placeholder="请输入内容"></el-input>
    <br/>
    <br/>
    <span>社团类型 &nbsp;&nbsp;</span>
    <el-select v-model="club.type" placeholder="请选择" :disabled="true" class="inputMax">
    </el-select>
    <br/>
    <br/>
    <span>创建时间 &nbsp;&nbsp;</span>
    <el-input
        prefix-icon="el-icon-date"
        :disabled="true"
        class="inputMax"
        v-model="createTime"
    ></el-input>
    <br/>
    <br/>
    <span>社团账号 &nbsp;&nbsp;</span>
    <el-input class="inputMax" v-model="club.username" placeholder="请输入内容"></el-input>
    <br/>
    <br/>
    <span>初始密码 &nbsp;&nbsp;</span>
    <el-input class="inputMax" v-model="club.pwd" placeholder="请输入内容"></el-input>
    <br/>
    <br/>
    <el-input
        type="textarea"
        :rows="2"
        placeholder="请输入社团简介"
        v-model="club.content">
    </el-input>
    <br/>
    <br/>
    <el-button type="primary" @click="toClubUpdate">修改</el-button>
  </div>
</template>

<script>
import {articleById, articleUpdate, clubById, clubUpdate} from '@/api'
export default {
  name: "ClubInfo",
  data() {
    return {
      createTime: '',
      club: {},
    }
  },

  created() {
    let club = {
      id: sessionStorage.getItem('cid'),
    };
    clubById(club).then((result)=>{
      this.club = result.data;
      this.createTime = result.data.createTime.substring(0,10);
    })
  },

  methods: {
    toClubUpdate(){
      let club = {
        id: sessionStorage.getItem('cid'),
        name: this.club.name,
        type: this.club.type,
        content: this.club.content,
        username: this.club.username,
        pwd: this.club.pwd,
      };
      this.$confirm('此操作将永久修改社团信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
       clubUpdate(club).then(()=>{
         clubById(club).then((result)=>{
           this.club = result.data;
           this.createTime = result.data.createTime.substring(0,10);
         })
       });
        this.$message({
          type: 'success',
          message: '修改成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消修改'
        });
      });
    }
  }
}
</script>

<style scoped>
.inputMax{
  width: 200px;
}
</style>
